GtkWidget: Fix clipping to large subwindows
authorAlexander Larsson <alexl@redhat.com>
Mon, 28 Oct 2013 10:32:51 +0000 (11:32 +0100)
committerAlexander Larsson <alexl@redhat.com>
Mon, 28 Oct 2013 10:56:52 +0000 (11:56 +0100)
_gtk_widget_draw_internal() was clipping by passing the subwindow
sizes as a path to cairo_clip(). This was breaking for windows
larger than 23 bits in width/height, due to cairo using fixed point
(24.8) for the path coordinates.

We fix this by pre-clipping the subwindow region to the existing
cairo clip region in the full 32bit gdkwindow precision. This fixes
the GooCanvas Large Items test.

https://bugzilla.gnome.org/show_bug.cgi?id=710958

gtk/gtkwidget.c

index 7acfd652b44938316103cf8d9dc5f74b73beb7fe..21d02f371934bb2e9e0131bfbf50b1ac9f23b548 100644 (file)
@@ -6491,18 +6491,33 @@ _gtk_widget_draw_windows (GdkWindow *window,
   gboolean do_clip;
   GtkWidget *widget = NULL;
   GList *children, *l;
+  GdkRectangle current_clip, window_clip;
   int x, y;
 
   if (!gdk_window_is_viewable (window))
     return;
 
+  window_clip.x = window_x;
+  window_clip.y = window_y;
+  window_clip.width = gdk_window_get_width (window);
+  window_clip.height = gdk_window_get_height (window);
+
+  /* Cairo paths are fixed point 24.8, but gdk supports 32bit window
+     sizes, so we can't feed window_clip to e.g. cairo_rectangle()
+     directly. Instead, we pre-clip the window clip to the existing
+     clip regions in full 32bit precision and feed that to cairo. */
+  if (!gdk_cairo_get_clip_rectangle (cr, &current_clip) ||
+      !gdk_rectangle_intersect (&window_clip, &current_clip, &window_clip))
+    return;
+
   cairo_save (cr);
-  cairo_translate (cr, window_x, window_y);
-  cairo_rectangle (cr, 0, 0,
-                  gdk_window_get_width (window),
-                  gdk_window_get_height (window));
+  cairo_rectangle (cr,
+                   window_clip.x, window_clip.y,
+                   window_clip.width, window_clip.height);
   cairo_clip (cr);
 
+  cairo_translate (cr, window_x, window_y);
+
   if (gdk_cairo_get_clip_rectangle (cr, NULL))
     {
       gdk_window_get_user_data (window, (gpointer *) &widget);